Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(simulation): Fix all problems make test-sim-custom-genesis-fast for simulation test. (backport #17911) #20909

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jul 9, 2024

cosmos sdk provides a powerful simulation testing capability, and one of the simulation modes TestFullAppSimulation allows for simulation testing using data from genesis.json. The original implementation can be found at #3428. However, with the release of v0.40.0, there have been significant changes to the code and TestFullAppSimulation is no longer being maintained.

The following are my steps:

To begin, the chain-related data can be initialized using the following command, at least 2 accounts must be added for genesis account, otherwise when executing SimulateMsgSend, two accounts will be selected to meet the conditions from != to and it will fall into an infinite loop.

simd init cosmos --chain-id simulation-app

simd keys add my_validator --keyring-backend test

MY_VALIDATOR_ADDRESS=$(simd keys show my_validator -a --keyring-backend test)

simd genesis add-genesis-account $MY_VALIDATOR_ADDRESS 100000000000stake
simd genesis add-genesis-account cosmos1gfg9ucc7rrzc207y9qfmf58erftzf8z8ww5lr7 100000000000stake
simd genesis add-genesis-account cosmos1lh6pmahlkytz7lmrs25a42j6kxlmztyt204kyq 100000000000stake
simd genesis add-genesis-account cosmos18v3mjs2pmssd03v0qz80fr0u2j5p7lxw8nchxg 100000000000stake

simd genesis gentx my_validator 100000000stake --chain-id simulation-app --keyring-backend test

simd genesis collect-gentxs

Then, in the latest main branch, execute the command make test-sim-custom-genesis-fast (note: you need to modify -Genesis=${HOME}/.gaiad/config/genesis.json to -Genesis=${HOME}/.simapp/config/genesis.json in the Makefile first). You may encounter the following error:

Running custom genesis simulation...
By default, /Users/lcq/.gaiad/config/genesis.json will be used.
=== RUN   TestFullAppSimulation
Starting SimulateFromSeed with randomness created with seed 99
Randomized simulation params: 
{}
Selected randomly generated consensus parameters:
{
 "block": {
  "max_bytes": 21456269,
  "max_gas": -1
 },
 "evidence": {
  "max_age_num_blocks": 302400,
  "max_age_duration": 1814400000000000
 },
 "validator": {
  "pub_key_types": [
   "ed25519"
  ]
 }
}
Starting the simulation from time Wed Sep 27 15:49:06 UTC 2023 (unixtime 1695829746)
Simulating... block 1/100, operation 0/269. Logs to writing to /Users/lcq/.simapp/simulations/2023-09-28_00:18:10.log
    simulate.go:347: error on block  1/100, operation (1/269) from x/group:
        group: not found [cosmos/cosmos-sdk/x/group/keeper/grpc_query.go:27]
        Comment: 
--- FAIL: TestFullAppSimulation (0.12s)
FAIL

Based on the errors encountered during each execution of make test-sim-custom-genesis-fast, I have identified and attempted to resolve three potential issues:

Issue 1: Fix the problem where the account randomly generated by AppStateFromGenesisFileFn does not have a ConsKey, causing SimulateMsgCreateValidator to fail.
This issue primarily arises when executing SimulateMsgCreateValidator. The accounts generated by AppStateFromGenesisFileFn do not have the ConsKey field specified, leading to a null pointer exception when calling simAccount.ConsKey.PubKey().

Issue 2: Fix the problem of operating on a group, such as SimulateMsgCreateGroupPolicy, when the group does not exist in the chain during simulation testing.
The problem is encountered when executing the simulation test of the group module. It occurs when there is no group created, meaning there is no group in the chain. Some operations are performed on an empty group, such as executing SimulateMsgCreateGroupPolicy.

Issue 3: Add the SigverifyTx flag in the simulation test whether to check the transaction signature.
During the execution of AppStateFromGenesisFileFn, the private keys corresponding to addresses are generated randomly. Therefore, when executing transactions, we need to skip the signature verification check.
Of course, if the genesis data is also randomly generated, such as the simulation test executed by the make test-sim-nondeterminism command, the private key corresponding to the address generated at this time is correct, and the signature needs to be verified at this time.
Or when we also read the data initialization chain from the genesis.json file. If the private keys corresponding to all addresses are passed in, we can also verify the signature at this time.
So I added a SigverifyTx flag that leaves it up to the user to decide whether signature verification of the transaction is required. For example, if I want to skip signature verification when executing simulation, then I can run go test -mod=readonly -run TestFullAppSimulation -Genesis=genesis.json -SigverifyTx=false


This is an automatic backport of pull request #17911 done by Mergify.

… for simulation test. (#17911)

Co-authored-by: Luke <chenqun.l@kaitaitech.cn>
(cherry picked from commit 611cd36)

# Conflicts:
#	CHANGELOG.md
Copy link
Contributor Author

mergify bot commented Jul 9, 2024

Cherry-pick of 611cd36 has failed:

On branch mergify/bp/release/v0.50.x/pr-17911
Your branch is up to date with 'origin/release/v0.50.x'.

You are currently cherry-picking commit 611cd36b8.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   Makefile
	modified:   baseapp/baseapp.go
	modified:   baseapp/options.go
	modified:   baseapp/test_helpers.go
	modified:   simapp/sim_test.go
	modified:   testutil/sims/state_helpers.go
	modified:   types/context.go
	modified:   x/auth/ante/sigverify.go
	modified:   x/auth/ante/sigverify_test.go
	modified:   x/group/simulation/operations.go
	modified:   x/simulation/client/cli/flags.go
	modified:   x/simulation/simulate.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   CHANGELOG.md

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@julienrbrt julienrbrt marked this pull request as ready for review July 11, 2024 08:24
@julienrbrt julienrbrt enabled auto-merge (squash) July 11, 2024 08:25
@julienrbrt julienrbrt merged commit 6986270 into release/v0.50.x Jul 11, 2024
43 of 45 checks passed
@julienrbrt julienrbrt deleted the mergify/bp/release/v0.50.x/pr-17911 branch July 11, 2024 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants